package com.gap.revision;

import com.buanalintas.bynga.Action;
import com.buanalintas.bynga.Controller;
import com.buanalintas.bynga.Dictionary;
import com.buanalintas.bynga.Field;
import com.buanalintas.bynga.Logger;
import com.buanalintas.bynga.Page;
import com.buanalintas.bynga.Page.Group;
import com.buanalintas.bynga.Persistence;
import com.buanalintas.bynga.Sequence;
import com.buanalintas.bynga.Utility;
import com.buanalintas.bynga.formatter.DateFormatter;
import com.buanalintas.bynga.formatter.MoneyFormatter;
import com.gap.employee.Employee;
import com.gap.entities.GapMasterEmployee;
import com.gap.entities.GapMasterHistoryEmployee;
import com.gap.entities.GapTransactionEmployee;
import com.gap.entities.GapTransactionEmployeeDetail;
import com.gap.entities.GapTransactionHistoryEmployee;
import com.gap.entities.GapTransactionRevision;
import com.gap.entities.GapTransactionRevisionDetail;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * Class Revision is ...
 *
 * Generated on Fri Jan 09 13:17:48 ICT 2015
 *
 * @version 1.0
 * @author Mr. Kazao™
 * @since Bynga 1.0
 *
 */
public class Revision extends Page {

    private Field revisionId;
    private Field revisionEmployeeName;
    private Field revisionEmployeeStatus;
    private Field revisionDate;
    private Field revisionItem;
    private Field revisionItemPrice;
    private Field revisionDiscount;
    private Field revisionLast;
    private Field revisionCurrent;
    private Field revisionValue;
    private Field revisionPlatform;
    private Field revisionNumber;
    private Field revisionKnownBy;
    private Field revisionDescription;
    private Field revisionTimestamp;
    private Field revisionPosId;
    private Field revisionEmployeeId;
    private Field revisionUnitId;
    private Field revisionUserId;

    public Revision() {
        super();

        setTheClass(GapTransactionRevision.class);
        setPageDetail(RevisionDetail.class);



        revisionId = new Field();
        revisionId.setName("revisionId");
        revisionId.setCaption("revision id");
        //revisionId.setInfo("revision id");
        revisionId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        revisionId.setInputProperties(" size=\"20\"");
        getFields().add(revisionId);

        revisionEmployeeName = new Field();
        revisionEmployeeName.setName("revisionEmployeeName");
        revisionEmployeeName.setCaption("employee name");
        revisionEmployeeName.setRequired(true);
        revisionEmployeeName.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        revisionEmployeeName.setInputProperties(" size=\"20\" readonly");
        getFields().add(revisionEmployeeName);

        revisionEmployeeStatus = new Field();
        revisionEmployeeStatus.setName("revisionEmployeeStatus");
        revisionEmployeeStatus.setCaption("status bonus");
        revisionEmployeeStatus.setRequired(true);
        revisionEmployeeStatus.setListProperties(" align=\"center\" width=\"1%\" nowrap");
        revisionEmployeeStatus.setInputProperties(" size=\"20\" readonly");
        getFields().add(revisionEmployeeStatus);

        revisionItem = new Field();
        revisionItem.setName("revisionItem");
        revisionItem.setCaption("item");
        revisionItem.setRequired(true);
        revisionItem.setListProperties(" align=\"center\" width=\"5%\" nowrap");
        revisionItem.setInputProperties(" size=\"20\" readonly");
        getFields().add(revisionItem);

        revisionDate = new Field();
        revisionDate.setName("revisionDate");
        revisionDate.setCaption("date");
        revisionDate.setRequired(true);
        revisionDate.setListProperties(" align=\"center\" width=\"1%\" nowrap");
        revisionDate.setInputProperties(" size=\"8\"");
        revisionDate.setDefaultValue(Utility.getTimestamp());
        getFields().add(revisionDate);

        revisionItemPrice = new Field();
        revisionItemPrice.setName("revisionItemPrice");
        revisionItemPrice.setCaption("price");
        revisionItemPrice.setRequired(true);
        revisionItemPrice.setFormater(MoneyFormatter.getInstance());
        revisionItemPrice.setListProperties(" align=\"right\" width=\"10%\" nowrap");
        revisionItemPrice.setInputProperties(" size=\"20\"");
        getFields().add(revisionItemPrice);

        revisionDiscount = new Field();
        revisionDiscount.setName("revisionDiscount");
        revisionDiscount.setCaption("discount ");
        revisionDiscount.setRequired(true);
        revisionDiscount.setListProperties(" align=\"right\" width=\"10%\" nowrap");
        revisionDiscount.setInputProperties(" size=\"20\" readonly");
        getFields().add(revisionDiscount);

        revisionLast = new Field();
        revisionLast.setName("revisionLast");
        revisionLast.setCaption("last");
        revisionLast.setFormater(MoneyFormatter.getInstance());
        revisionLast.setListProperties(" align=\"right\" width=\"1%\" nowrap");
        revisionLast.setInputProperties(" size=\"20\"");
        getFields().add(revisionLast);

        revisionCurrent = new Field();
        revisionCurrent.setName("revisionCurrent");
        revisionCurrent.setCaption("saldo");
        revisionCurrent.setFormater(MoneyFormatter.getInstance());
        revisionCurrent.setListProperties(" align=\"right\" width=\"10%\" nowrap");
        revisionCurrent.setInputProperties(" size=\"20\"");
        getFields().add(revisionCurrent);

        revisionValue = new Field();
        revisionValue.setName("revisionValue");
        revisionValue.setCaption("value");
        revisionValue.setFormater(MoneyFormatter.getInstance());
        revisionValue.setListProperties(" align=\"right\" width=\"10%\" nowrap");
        revisionValue.setInputProperties(" size=\"20\" readonly");
        getFields().add(revisionValue);

        revisionPlatform = new Field();
        revisionPlatform.setName("revisionPlatform");
        revisionPlatform.setCaption("platform");
        revisionPlatform.setRequired(true);
        revisionPlatform.setFormater(MoneyFormatter.getInstance());
        revisionPlatform.setListProperties(" align=\"right\" width=\"10%\" nowrap");
        revisionPlatform.setInputProperties(" size=\"20\" readonly");
        getFields().add(revisionPlatform);

        revisionNumber = new Field();
        revisionNumber.setName("revisionNumber");
        revisionNumber.setCaption("number");
        revisionNumber.setRequired(true);
        revisionNumber.setListProperties(" align=\"center\" width=\"15%\" nowrap");
        revisionNumber.setInputProperties(" size=\"50\" readonly");
        getFields().add(revisionNumber);

        revisionKnownBy = new Field();
        revisionKnownBy.setName("revisionKnownBy");
        revisionKnownBy.setCaption("known by");
        //revisionKnownBy.setInfo("revision known by");
        revisionKnownBy.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        revisionKnownBy.setInputProperties(" size=\"30\"");
        getFields().add(revisionKnownBy);

        revisionDescription = new Field();
        revisionDescription.setName("revisionDescription");
        revisionDescription.setCaption("description");
        //revisionDescription.setInfo("revision description");
        revisionDescription.setListProperties(" width=\"20%\"");
        revisionDescription.setInputProperties(" cols=\"50\" rows=\"5\"");
        revisionDescription.setInputType(Field.INPUT_TEXT_AREA);
        getFields().add(revisionDescription);

        revisionTimestamp = new Field();
        revisionTimestamp.setName("revisionTimestamp");
        revisionTimestamp.setCaption("timestamp");
        //revisionTimestamp.setInfo("revision timestamp");
        revisionTimestamp.setListProperties(" align=\"center\" width=\"1%\" nowrap");
        revisionTimestamp.setInputProperties(" size=\"12\"");
        //revisionTimestamp.setFormatter(DateFormatter.getInstanceDateTime(this));
        getFields().add(revisionTimestamp);

        revisionPosId = new Field();
        revisionPosId.setName("revisionPosId");
        revisionPosId.setCaption("transaction");
        revisionPosId.setRequired(true);
        revisionPosId.setSelectorLoad(true);
        revisionPosId.setSelectorCondition(" t.posStatus is NULL");
        revisionPosId.setSelectorOrder("t.posTimestamp DESC");
        revisionPosId.getSelectorAction().add(new String[]{"value", "revisionEmployeeName", "posEmployeeName"});
        revisionPosId.getSelectorAction().add(new String[]{"value", "revisionEmployeeStatus", "posEmployeeStatus"});
        revisionPosId.getSelectorAction().add(new String[]{"value", "revisionPlatform", "posPlatform"});
        revisionPosId.getSelectorAction().add(new String[]{"value", "revisionCodeItem", "posCodeItem"});
        revisionPosId.getSelectorAction().add(new String[]{"value", "revisionItem", "posItemName"});
        revisionPosId.getSelectorAction().add(new String[]{"value", "revisionItemPrice", "posItemPrice"});
        revisionPosId.getSelectorAction().add(new String[]{"value", "revisionDiscount", "posDiscount"});
        revisionPosId.getSelectorAction().add(new String[]{"value", "revisionValue", "posValue"});
        revisionPosId.getSelectorColumns().add(new String[]{"posNumber", "Number", "width=\"20%\" nowrap"});
        revisionPosId.getSelectorColumns().add(new String[]{"posEmployeeId", "ID Employee", "width=\"10%\""});
        revisionPosId.getSelectorColumns().add(new String[]{"posEmployeeName", "Name", "width=\"30%\""});
        revisionPosId.getSelectorColumns().add(new String[]{"posEmployeeStatus", "Status", "width=\"10%\" nowrap"});
        revisionPosId.getSelectorColumns().add(new String[]{"posPlatform", "Platform", "width=\"10%\" nowrap"});
        revisionPosId.getSelectorColumns().add(new String[]{"posCurrent", "Saldo", "width=\"10%\" nowrap"});
        revisionPosId.setListProperties(" align=\"center\" width=\"15%\" nowrap");
        revisionPosId.setInputProperties(" size=\"30\"");
        getFields().add(revisionPosId);

        revisionEmployeeId = new Field();
        revisionEmployeeId.setName("revisionEmployeeId");
        revisionEmployeeId.setCaption("employee");
        revisionEmployeeId.setRequired(true);
        revisionEmployeeId.setListProperties(" align=\"center\" width=\"1%\" nowrap");
        revisionEmployeeId.setInputProperties(" size=\"20\"");
        getFields().add(revisionEmployeeId);

        revisionUnitId = new Field();
        revisionUnitId.setName("revisionUnitId");
        revisionUnitId.setCaption("unit");
        //revisionUnitId.setInfo("revision unit id");
        revisionUnitId.setListProperties(" align=\"center\" width=\"1%\" nowrap");
        revisionUnitId.setInputProperties(" size=\"20\"");
        getFields().add(revisionUnitId);

        revisionUserId = new Field();
        revisionUserId.setName("revisionUserId");
        revisionUserId.setCaption("user");
        //revisionUserId.setInfo("revision user id");
        revisionUserId.setListProperties(" align=\"center\" width=\"1%\" nowrap");
        revisionUserId.setInputProperties(" size=\"20\"");
        getFields().add(revisionUserId);


        getActions().add(Action.TRANS_ADD);
        getActions().add(Action.TRANS_EDIT);
        getActions().add(Action.TRANS_VIEW);
        fillFields();
        getFieldsAdd().clear();
        getGroupsAdd().add(new Group("Transaction",
                revisionDate,
                revisionNumber,
                revisionPosId));
        getGroupsAdd().add(new Group("Employee",
                //                revisionEmployeeId,
                revisionEmployeeName,
                revisionEmployeeStatus,
                revisionPlatform));
        getGroupsAdd().add(new Group("Item",
                revisionItem,
                revisionItemPrice,
                revisionDiscount));

        getGroupsEdit().add(new Group("Transaction",
                revisionDate,
                revisionNumber,
                revisionPosId));
        getGroupsEdit().add(new Group("Employee",
                //                revisionEmployeeId,
                revisionEmployeeName,
                revisionEmployeeStatus,
                revisionPlatform));
//        getGroupsEdit().add(new Group("Item",
//                revisionItem,
//                revisionItemPrice,
//                revisionDiscount));


        getFieldsList().clear();
        getFieldsList().add(revisionDate);
        getFieldsList().add(revisionNumber);
//        getFieldsList().add(revisionKnownBy);
        getFieldsList().add(revisionPosId);
        getFieldsList().add(revisionEmployeeName);
        getFieldsList().add(revisionEmployeeStatus);
        getFieldsList().add(revisionPlatform);
//        getFieldsList().add(revisionItem);
//        getFieldsList().add(revisionItemPrice);
//        getFieldsList().add(revisionDiscount);
        getFieldsList().add(revisionValue);
        getFieldsList().add(revisionDescription);

        getFieldsView().clear();
        getGroupsView().add(new Group("Transaction",
                revisionDate,
                revisionNumber,
                revisionUnitId,
                revisionUserId,
                revisionPosId));
        getGroupsView().add(new Group("Employee",
                revisionEmployeeId,
                revisionEmployeeName,
                revisionEmployeeStatus,
                revisionPlatform));
//        getGroupsView().add(new Group("Item",
//                revisionItem,
//                revisionItemPrice,
//                revisionDiscount));
        getGroupsView().add(new Group("Value",
                revisionLast, revisionValue, revisionCurrent));

        setController(new RevisionController(this));
        setExportList(getClass().getResourceAsStream("RevisionList.jasper"));
        setExport(getClass().getResourceAsStream("Revision.jasper"));
    }

    @Override
    public String validate(Object data, List list) {
        EntityManager em = getEntityManager();
        GapTransactionRevision revisi = (GapTransactionRevision) data;
        GapTransactionEmployee employ = revisi.getRevisionPosId();
        GapTransactionHistoryEmployee history = new GapTransactionHistoryEmployee();
        GapMasterHistoryEmployee masterhis = Employee.getStock(em, revisi.getRevisionPosId().getPosEmployeeId());

        int value = masterhis.getHistoryValue().intValue();

        BigDecimal Saldo = BigDecimal.ZERO;

        //--------EMPLOYEEE-----------
        GapMasterEmployee mase = null;
        try {
            mase = (GapMasterEmployee) em.createQuery("SELECT t FROM GapMasterEmployee t WHERE t.employeeId='" + revisi.getRevisionPosId().getPosEmployeeId().getEmployeeId() + "'").setHint(Persistence.REFRESH_HINT, true).getSingleResult();
            System.out.println("x mase jose ---->" + mase);
        } catch (Exception e) {
            Logger.getInstance().log(e);
            System.out.println("x eeeeee :" + e);
        }

        //-----ITEM------
        BigDecimal hargaTrans = revisi.getRevisionPosId().getPosValue();
        BigDecimal nambahnya = BigDecimal.ZERO;
        BigDecimal persent = BigDecimal.ZERO;
        BigDecimal persent2 = BigDecimal.ZERO;

//        hargaTrans = employ.getPosItemPrice().subtract(employ.getPosDiscountNominal());
        BigDecimal totNet = BigDecimal.ZERO;

        for (int i = 0; i < list.size(); i++) {
            List<GapTransactionRevisionDetail> details = list;
            totNet = totNet.add(details.get(i).getRevisionDetailNett());
        }

        int bandingkan = 0;
        bandingkan = totNet.compareTo(hargaTrans);
        //********JIKA Harga REVISI Lebih Besar***********
        //===============================================
        if (bandingkan == 1) {
            nambahnya = totNet.subtract(hargaTrans);
            System.out.println("x nambahnya 1---->" + nambahnya);

            Saldo = masterhis.getHistoryValue().subtract(nambahnya);
            System.out.println("x Saldo 2 ---->" + Saldo);

            //********JIKA Harga REVISI Lebih Kecil***********
            //===============================================
        } else if (bandingkan == -1) {
            nambahnya = hargaTrans.subtract(totNet);
            System.out.println("x nambahnya -1---->" + nambahnya);

            Saldo = masterhis.getHistoryValue().add(nambahnya);
            System.out.println("x Saldo 3 ---->" + Saldo);
            revisi.setRevisionCurrent(Saldo);

        } else if (bandingkan == 0) {
            nambahnya = totNet;
            System.out.println("x nambahnya 0---->" + nambahnya);
        }
//        if (hargaRev.intValue() > value || nambahnya.intValue() < 0) {
        if (nambahnya.intValue() < 0 || Saldo.intValue() < 0) {
            return Dictionary.getValue(this, "Saldo bulan ini sebesar Rp " + value
                    + " dan nilai transaksi anda sebesar Rp " + totNet);
        }

        return null;
    }

    @Override
    public void afterInit(HttpServletRequest req, HttpServletResponse res) {
        revisionDate.setFormater(DateFormatter.getInstanceDate(this));
        revisionTimestamp.setFormater(DateFormatter.getInstanceDateTime(this));

    }

    @Override
    public void beforeAdd() {
        revisionNumber.setDefaultValue(generate());
    }

    class RevisionController extends Controller {

        public RevisionController(Page page) {
            super(page);
            setOrder(revisionTimestamp);
            setOrderType("DESC");
        }

        @Override
        public void beforeInsert(Object data, List detail) {
            EntityManager em = getEntityManager();
            GapTransactionRevision revisi = (GapTransactionRevision) data;
            GapTransactionEmployee employ = revisi.getRevisionPosId();
            revisi.setRevisionNumber(generate());
            revisi.setRevisionUnitId(getCurrentUnit());
            revisi.setRevisionUserId(getCurrentUser());
            revisi.setRevisionTimestamp(Utility.getTimestamp());
            revisi.setRevisionEmployeeId(employ.getPosEmployeeId());
            revisi.getRevisionPosId().setPosDescription("Revision by " + revisi.getRevisionUserId());

            GapMasterHistoryEmployee masterhis = Employee.getStock(em, revisi.getRevisionEmployeeId());
            GapTransactionHistoryEmployee history = new GapTransactionHistoryEmployee();

            revisi.setRevisionLast(masterhis.getHistoryValue());
            System.out.println("LAST :" + revisi.getRevisionLast());
            BigDecimal Saldo = BigDecimal.ZERO;

            BigDecimal totNet = BigDecimal.ZERO;

            for (int i = 0; i < detail.size(); i++) {
                List<GapTransactionRevisionDetail> details = detail;
                totNet = totNet.add(details.get(i).getRevisionDetailNett());
            }

            revisi.setRevisionValue(totNet);

            //--------EMPLOYEEE-----------
            GapMasterEmployee mase = null;
            try {
                mase = (GapMasterEmployee) em.createQuery("SELECT t FROM GapMasterEmployee t WHERE t.employeeId='" + revisi.getRevisionEmployeeId().getEmployeeId() + "'").setHint(Persistence.REFRESH_HINT, true).getSingleResult();
                System.out.println("mase  ---->" + mase);
            } catch (Exception e) {
                Logger.getInstance().log(e);
                System.out.println("eeeeee :" + e);
            }

            BigDecimal nambahnya = BigDecimal.ZERO;
            BigDecimal hargaTrans = revisi.getRevisionPosId().getPosValue();
            int bandingkan = 0;
            bandingkan = totNet.compareTo(hargaTrans);
            //********JIKA Harga REVISI Lebih Besar***********
            //===============================================
            if (bandingkan == 1) {
                nambahnya = totNet.subtract(hargaTrans);
                System.out.println("nambahnya 1---->" + nambahnya);

                Saldo = masterhis.getHistoryValue().subtract(nambahnya);
                System.out.println("Saldo 2 ---->" + Saldo);


                if (Saldo.intValue() < 0) {
                    Saldo = Saldo.multiply(new BigDecimal(-1));
                    System.out.println("Saldo -2 ---->" + Saldo);
                }
                revisi.setRevisionCurrent(Saldo);
                //********JIKA Harga REVISI Lebih Kecil***********
                //===============================================
            } else if (bandingkan == -1) {
                nambahnya = hargaTrans.subtract(totNet);
                System.out.println("nambahnya -1---->" + nambahnya);

                Saldo = masterhis.getHistoryValue().add(nambahnya);
                System.out.println("Saldo 3 ---->" + Saldo);
                revisi.setRevisionCurrent(Saldo);

            } else if (bandingkan == 0) {
                nambahnya = totNet;
                System.out.println("nambahnya 0---->" + nambahnya);
            }
            revisi.getRevisionPosId().setPosStatus("Cancel");
            revisi.getRevisionPosId().setPosValue(revisi.getRevisionValue());
            System.out.println("1 0---->" + revisi.getRevisionPosId().getPosValue());
            revisi.getRevisionPosId().setPosCurrent(revisi.getRevisionCurrent());
            System.out.println("2 0---->" + revisi.getRevisionPosId().getPosCurrent());
        }

        @Override
        public void afterInsert(Object data, List list) {
            EntityManager em = getEntityManager();
            em.getTransaction().begin();
            GapTransactionRevision revisi = (GapTransactionRevision) data;
            System.out.println("jose 1---->" + revisi);

            for (Object detail : list) {
                GapTransactionRevisionDetail revdetail = (GapTransactionRevisionDetail) detail;

                GapTransactionEmployeeDetail emDetail = (GapTransactionEmployeeDetail) em.createQuery("SELECT t FROM GapTransactionEmployeeDetail t "
                        + "WHERE t.posDetailPosId.posId="
                        + revisi.getRevisionPosId().getPosId()
                        + " AND t.posDetailItemId.itemId ="
                        + revdetail.getRevisionDetailItemId().getItemId()).
                        setHint(Persistence.REFRESH_HINT, true).getSingleResult();
                System.out.println("Po --->" + emDetail);
            }

            GapMasterHistoryEmployee masterhis = Employee.getStock(em, revisi.getRevisionEmployeeId());
            GapTransactionHistoryEmployee history = new GapTransactionHistoryEmployee();

            history.setHistoryId(Sequence.next(history));
            history.setHistoryEmployeeId(revisi.getRevisionEmployeeId());
            history.setHistoryUnitId(getCurrentUnit());
            history.setHistoryUserId(getCurrentUser());
            history.setHistoryDate(revisi.getRevisionDate());
            history.setHistoryStatus("Revision" + " - " + getCurrentUser().getUserUname());
            history.setHistoryNumber(revisi.getRevisionNumber());
            history.setHistoryEmployeeName(revisi.getRevisionEmployeeName());
            history.setHistoryPlatform(revisi.getRevisionPlatform());
            history.setHistoryLast(masterhis.getHistoryValue());
            history.setHistoryCurrent(revisi.getRevisionCurrent());
            history.setHistoryValue(revisi.getRevisionValue());
            history.setHistoryDescription(revisi.getRevisionPosId().getPosNumber());
            history.setHistoryType("2");
            history.setHistoryTimestamp(revisi.getRevisionTimestamp());
            em.persist(history);
            masterhis.setHistoryValue(history.getHistoryCurrent());
            System.out.println("Curreennnttt ---->" + history.getHistoryCurrent());
            masterhis.setHistoryTimestamp(history.getHistoryTimestamp());
            masterhis.setHistoryUnitId(history.getHistoryUnitId());
            masterhis.setHistoryEmployeeId(history.getHistoryEmployeeId());
            masterhis.setHistoryEmployeeName(history.getHistoryEmployeeName());
            masterhis.setHistoryPlatform(history.getHistoryPlatform());
            masterhis.setHistoryDate(revisi.getRevisionDate());

//            GapTransactionHistoryEmployee mase = null;
            try {
                List<GapTransactionHistoryEmployee> hisss = getEntityManager().createQuery("SELECT t FROM GapTransactionHistoryEmployee t WHERE t.historyEmployeeId.employeeId='" + revisi.getRevisionEmployeeId().getEmployeeId() + "'").setHint(Persistence.REFRESH_HINT, true).getResultList();
                for (GapTransactionHistoryEmployee st : hisss) {
                    if (st.getHistoryTimestamp().equals(revisi.getRevisionPosId().getPosTimestamp())) {
                        st.setHistoryStatus("Cancel");
                        System.out.println("m status ---->" + st.getHistoryStatus());
                    }
                }
            } catch (Exception e) {
                Logger.getInstance().log(e);
                System.out.println("m eeeeee :" + e);
            }

            em.getTransaction().commit();
        }
    }

    public String generate() {
        String unitCode = getCurrentUnit().getUnitCode();
        Calendar cal = Calendar.getInstance();
        String year = "" + cal.get(Calendar.YEAR);
        String month = Utility.intToRoman(cal.get(Calendar.MONTH) + 1);
        try {
            GapTransactionRevision employee = (GapTransactionRevision) getEntityManager().createQuery("SELECT t FROM GapTransactionRevision t WHERE t.revisionNumber LIKE '%/" + unitCode + "/GAP/%/" + year + "' ORDER BY t.revisionTimestamp DESC").setHint(Persistence.REFRESH_HINT, true).setFirstResult(0).setMaxResults(1).getSingleResult();
            return Utility.lpad(Integer.parseInt(employee.getRevisionNumber().substring(0, 4)) + 1, 4, "0") + "/" + unitCode + "/GAP/" + month + "/" + year;
        } catch (Exception e) {
        }
        return "0001/" + unitCode + "/Revision/" + month + "/" + year;
    }

    @Override
    public void beforeExport() {
        getExportParams().put("title", Dictionary.getValue(this, "Transaction Revision"));
    }

    @Override
    public void beforeExportMulti() {
        beforeExport();
    }
}
